package com.wwwc.index.web.listeners;

import javax.servlet.*;
import com.wwwc.index.web.ejb.database.*;
//import com.wwwc.index.web.database.*;

public final class ContextListener implements ServletContextListener {
    private ServletContext context = null;
    private EJBDatabaseQuery ejbdb;
    
    public void contextInitialized (ServletContextEvent event) {
	context = event.getServletContext();

	try {
	    ejbdb = (new DatabaseEJBQuery()).getEJBDatabaseQuery();
	    //System.out.println(ejbdb.select("SELECT * FROM USERS WHERE USERNAME='WILLIAM';"));
	    context.setAttribute("ejbdb", ejbdb);
	} catch (Exception ex) {
	    //System.out.println("Couldn't create bookstore database bean[ContextListener]: " + ex.getMessage());
	}
    }
      
    public void contextDestroyed(ServletContextEvent event) {
	context = event.getServletContext();
	context.removeAttribute("ejbdb");
    }
}
